home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CEDITOR_
/
CUNDOTAS.C
< prev
next >
Wrap
Text File
|
1992-01-12
|
4KB
|
136 lines
/***************************************************************************************
CUndoTask.c SUPERCLASS = CTask
Provides UNDO capability by a brute force method: a copy of a CEditor object is
made, including all of the text. When UNDO is selected, the copy is swapped with
the latest version, effectively UNDOing the last changes. REDO is handled the
same way.
Could easily be improved by reducing memory requirements by storing only the
information required to convert existing text to an earlier version.
Copyright ⌐ BRH Toolsmith, 1992. All rights reserved.
Developed using THINK C 4.0.2 and Symantec's OOP libraries.
Portions of this code courtesy Symantec, Inc.
This code may be freely distributed as long as this notice remains. If you wish
to distribute modifications to these classes, please make a copy of the class
and implement your changes there. That's the beauty of OOP!
NOTE: tabs in this file are set at 4 in THINK C.
***************************************************************************************/
#include "CUndoTask.h"
#include <CApplication.h>
#include <CError.h>
#include <CScrollPane.h>
extern CApplication *gApplication;
extern CError *gError;
/***************************************************************************************
IUndoTask Method
Store given values.
***************************************************************************************/
void CUndoTask :: IUndoTask( CEditor *anEditor, CEditor *aCopy, short aTask )
{
inherited::ITask( aTask );
oldEditor = aCopy;
newEditor = anEditor;
}
/***************************************************************************************
Dispose Method *** OVERRIDE ***
Dispose of CEditor copy and then do ourselves in.
***************************************************************************************/
void CUndoTask :: Dispose( void )
{
oldEditor->Dispose();
inherited::Dispose();
}
/***************************************************************************************
Undo Method *** OVERRIDE ***
Make a copy of the current CEditor object. Replace the new one with the contents of
the old one, and make the old one point to the copy of the new one.
***************************************************************************************/
void CUndoTask :: Undo( void )
{
Handle src, dst, copy;
long size;
CScrollPane *aScrollPane;
/*
* Reset just in case
*/
oldEditor->activeUndo = FALSE;
/*
* Get references to both old and new editor versions.
* Make a copy of the new one for use later.
*/
src = (Handle )oldEditor;
copy = dst = (Handle )newEditor;
size = GetHandleSize( src );
gApplication->RequestMemory( FALSE, TRUE );
HandToHand( © );
gApplication->RequestMemory( FALSE, FALSE );
/*
* Copy contents of old CEditor object into current CEditor object
*/
HLock( src );
HLock( dst );
BlockMove( *src, *dst, size );
HUnlock( src );
HUnlock( dst );
/*
* Free our old version and store the handle to the new copy.
*/
if ( copy ) {
DisposHandle( src );
oldEditor = (CEditor *)copy;
}
else {
gError->PostAlert( 5000, 1 );
}
/*
* If the CEditor has a controlling scroll pane, update it
*/
aScrollPane = newEditor->itsScrollPane;
if ( aScrollPane ) {
aScrollPane->AdjustScrollMax();
aScrollPane->Calibrate();
}
/*
* Redraw entire frame (what a waste...)
*/
newEditor->Refresh();
}
/***************************************************************************************
Redo Method *** OVERRIDE ***
Just do the same thing as our Undo method.
***************************************************************************************/
void CUndoTask :: Redo( void )
{
Undo();
}